home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 19 / Night Owl (The Best of Shareware)(NOPV 19)(1996).ISO / 007a / strakd10.zip / STRAK.MEX < prev   
Text File  |  1995-11-18  |  4KB  |  197 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // StarTraker V1.00 [Door Count Module] (!)1995 Larry Monte\StarLab Systems
  4. //
  5. // MEX: Copyright 1990, 1995 by Lanius Corporation.  All rights reserved.
  6. //
  7. //
  8.  
  9. #define DO_DOORNAME 1
  10. #define DO_ENTRY    21
  11. #define DO_LAST     26
  12. #define DO_LASTUSR  44
  13. #define DO_RESET    62
  14.  
  15. #define LEN_DOORNAME 20
  16. #define LEN_ENTRY     5
  17. #define LEN_LAST     18
  18. #define LEN_LASTUSR  18
  19. #define LEN_RESET     9
  20. #define LEN_RECORD   77
  21.  
  22. #define CONFIG       "C:\\MAX\\STRAK\\STRAK.CTL"
  23. #define DAT_FILE     "C:\\MAX\\STRAK\\STRAK.DAT"
  24.  
  25. #include <max.mh>
  26.  
  27.  
  28. string: doorname,dstr,data,reset,lastuser,last,fname,entry;
  29. long: atofs,entery,fileoffset;
  30.  
  31.  
  32. struct _doorconfig
  33. {
  34.   string: tagname;
  35.   string: doorname;
  36. };
  37.  
  38. array [1..50] of struct _doorconfig: dc;
  39.  
  40. int get_configdata(ref int: i)
  41. {
  42.   int: dd,pos;
  43.  
  44.  
  45.   dd:=open(CONFIG, IOPEN_READ);
  46.   if (dd=-1)
  47.     print(COL_LRED, "Error!");
  48.  
  49.   i := 1;
  50.   while (readln(dd,data)>0)
  51.   {
  52.     if (data[1]<>';')
  53.     {
  54.       dc[i].tagname  := strtok(data, ",",pos);
  55.       dc[i].doorname := substr(data,pos+1,strlen(data));
  56.       i:=i+1;
  57.     }
  58.     pos:=0;
  59.   }
  60.   close(dd);
  61.   return i;
  62. }
  63.  
  64.  
  65. string getdoorname(string: argv, ref string: doordata, int: numdoors)
  66. {
  67.   int: i;
  68.  
  69.   for (i:=numdoors;i>0;i:=i-1)
  70.   {
  71.     if (argv = dc[i].tagname)
  72.     {
  73.       doordata := dc[i].doorname;
  74.       log("PEntered "+doordata+"!");
  75.       return doordata;
  76.     }
  77.   }
  78.   print(COL_RED, "Error Has Occured! Please inform Sysop!");
  79.   menu_cmd(106,"");
  80. }
  81.  
  82.  
  83. void packstr(ref string: s, string: u, int: ofs, int: len)
  84. {
  85.   int: c;
  86.   u := strpad(u, len, ' ');
  87.   for (c := 1; c <= len; c:=c+1)
  88.   {
  89.     s[ofs] := u[c];
  90.     ofs := ofs+1;
  91.   }
  92. }
  93.  
  94. string unpackstr(ref string: s, int: ofs, int: len)
  95. {
  96.   return strtrim(substr(s, ofs, len), " ");
  97. }
  98.  
  99. void unpackdata(ref string: s)
  100. {
  101.  
  102.   doorname := unpackstr(s, DO_DOORNAME, LEN_DOORNAME);
  103.   entry := unpackstr(s, DO_ENTRY, LEN_ENTRY);
  104.   dstr := unpackstr(s, DO_LAST, LEN_LAST);
  105.   lastuser := unpackstr(s, DO_LASTUSR, LEN_LASTUSR);
  106.   reset := unpackstr(s, DO_RESET, LEN_RESET);
  107.   entery := strtol(entry);
  108. }
  109.  
  110. int readdata(string: doordata)
  111. {
  112.   int: fd;
  113.  
  114.   fileoffset := -1;
  115.  
  116.   fd := open(DAT_FILE,IOPEN_READ);
  117.   if (fd<>-1)
  118.   {
  119.     int: done;
  120.  
  121.     atofs := 0;
  122.     done := False;
  123.  
  124.     while (done = False AND (read(fd,data,LEN_RECORD)=LEN_RECORD))
  125.     {
  126.       doorname:=unpackstr(data,DO_DOORNAME,LEN_DOORNAME);
  127.       if (doorname=doordata)
  128.       {
  129.         fileoffset := atofs;
  130.         unpackdata(data);
  131.         done := True;
  132.       }
  133.       atofs := atofs+LEN_RECORD;
  134.     }
  135.     close(fd);
  136.   }
  137.   return True;
  138. }
  139.  
  140. void packdata(ref string: s, string: doordata)
  141. {
  142.   int: pos;
  143.   struct _stamp: now;
  144.  
  145.   timestamp(now);
  146.   dstr := stamp_string(now);
  147.  
  148.   s := strpad("", LEN_RECORD, ' ');
  149.   packstr(s, doordata,      DO_DOORNAME,   LEN_DOORNAME);
  150.   entery := entery +1;
  151.   if (entery = 1)
  152.     reset := strtok(dstr, " \t",pos);
  153.   entry := strpadleft(ltostr(entery),5,' ');
  154.   packstr(s, entry,         DO_ENTRY,      LEN_ENTRY);
  155.   packstr(s, dstr,          DO_LAST,       LEN_LAST);
  156.   packstr(s, usr.name,      DO_LASTUSR,    LEN_LASTUSR);
  157.   packstr(s, reset,         DO_RESET,      LEN_RESET);
  158.  
  159.   s[LEN_RECORD-1]:='\r';
  160.   s[LEN_RECORD-0]:='\n';
  161. }
  162.  
  163. int writedata(ref string: doordata)
  164. {
  165.   int: fd;
  166.  
  167.   packdata(data, doordata);
  168.   fd := open(DAT_FILE,IOPEN_RW);
  169.   if (fd = -1)
  170.   {
  171.     fd := open(DAT_FILE,IOPEN_RW|IOPEN_CREATE);
  172.     if (fd = -1)
  173.       menu_cmd(106,"");
  174.       return False;
  175.   }
  176.   if (fileoffset = -1)
  177.     fileoffset := seek(fd,0,SEEK_END);
  178.   seek(fd,fileoffset,SEEK_SET);
  179.   write(fd,data,LEN_RECORD);
  180.   close(fd);
  181.   return True;
  182. }
  183.  
  184.  
  185. int main(string: argv)
  186. {
  187.   string: doordata;
  188.   int: fd, numdoors;
  189.  
  190.   get_configdata(numdoors);
  191.   getdoorname(argv, doordata, numdoors);
  192.   readdata(doordata);
  193.   writedata(doordata);
  194.   return 0;
  195. }
  196.     
  197.